Meaningful Places & Where to Find them

Places and pathways

# Get Places data
t <- "20201216_104624"
data.places.physical <- readRDS(paste("data/places.physical_" , t, ".rds"))
# Define bounding box for our region of New Haven (will be the default zoom
# level of our visualization), but also define a slightly larger bounding box
# to give some more border in case viewers want to zoom out.
x.lim0 <- c(-72.939, -72.903)
y.lim0 <- c(41.302, 41.332)
x.lim <- x.lim0 + 0.04 * c(-1, 1)
y.lim <- y.lim0 + 0.02 * c(-1, 1)
p_jitter <- data.places.physical %>%
    st_crop(xmin=x.lim[1], xmax=x.lim[2], ymin=y.lim[1], ymax=y.lim[2]) %>%
    st_jitter()
p_jitter['x'] <- map_dbl(p_jitter$geometry, ~.[1])
p_jitter['y'] <- map_dbl(p_jitter$geometry, ~.[2])
# Get map data
# newhaven_lowres <- get_stamenmap(bbox=c(left=x.lim[1], right=x.lim[2], bottom=y.lim[1], top=y.lim[2]), zoom=15)
# newhaven <- get_stamenmap(bbox=c(left=x.lim0[1], right=x.lim0[2], bottom=y.lim0[1], top=y.lim0[2]), zoom=17)
# saveRDS(newhaven_lowres, "data/newhaven_lowres.rds", compress=F)
# saveRDS(newhaven, "data/newhaven.rds", compress=F)
newhaven_lowres <- readRDS("data/newhaven_lowres.rds")
newhaven <- readRDS("data/newhaven.rds")

Simplefeatures are great, but we actually end up using rasters. This allows the viewer to see precise building outlines on the map (while remaining feasible to render and interact with on a normal computer/browser). In addition, geom_density_2d() needs x,y data rather than simplefeatures.1

g <- ggmap(newhaven_lowres) +
    inset_ggmap(newhaven) +
    geom_density_2d(data=p_jitter, aes(x=x, y=y), size=0.4, alpha=0.8, bins=15) + # Sadly, plotly isn't ready for density_2d_filled
    geom_point(data=p_jitter, aes(x=x, y=y), color="yellow", alpha=0.9, size=0.6) +
    lims(x=x.lim0, y=y.lim0) +
    theme(axis.text=element_blank(), axis.ticks=element_blank(), axis.title=element_blank())

ggplotly(g)

Not a huge surprise: very large cluster around Ezra Stiles College. Note the little Koffee? bump. And a good little cluster around East Rock (and one West Rock).

Virtual realm

t <- "20201216_104624"
data.places.virt <- read.csv(paste("data/places.virt_" , t, ".csv"))

The venerable word cloud lives to see another day:

set.seed(2021)
places <- data.places.virt %>%
    mutate(angle = 90 * sample(c(0, 1), n(), replace=T, prob=c(60, 40))) %>%
    mutate(size = sample(c(10.4, 10.7, 11, 11.2), n(), replace=T, prob=c(31, 23, 23, 23)))
    
ggplot(places, aes(label=Name, angle=angle, size=size)) +
    # https://cran.r-project.org/web/packages/ggwordcloud/vignettes/ggwordcloud.html
    geom_text_wordcloud_area(family="Serif") +
    theme_tufte()


  1. https://stackoverflow.com/questions/51566685/plotting-a-kernel-map-based-on-points-with-geom-sf↩︎